package cn.edu.ahstu;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;

public class WordCountMapper extends Mapper<LongWritable,Text, Text, IntWritable>{
    @Override
    protected void map(LongWritable key,Text value,Mapper<LongWritable,Text,Text,IntWritable>.Context context) throws IOException,InterruptedException{
//        接收传入的一行文本数据，将数据类型转化为String类型
        String line = value.toString();
//        将这行文本数据的内容按照空格进行分割
        String[] words = line.split(" ");
//        遍历数组
        for(String word : words){
            context.write(new Text(word),new IntWritable(1));
        }
    }
}

